
package com.rx.mgt.controller;  

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rx.mgt.dao.SysStoreService;
import com.rx.mgt.domain.AdminUser;
import com.rx.mgt.domain.ScheduleTask;
import com.rx.mgt.domain.SysStore;
import com.rx.mgt.po.UsersBo;
import com.rx.mgt.service.DomainService;
import com.rx.mgt.service.ScheduleTaskService;
import com.rx.mgt.service.SysLogService;
import com.rx.mgt.util.IpUtil;

/** 
 * ClassName:SysStoreController 
 * Function :
 * Reason   : 
 * Date     :Feb 6, 2017 1:14:55 PM 
 * @author   luolei 
 * @since    JDK 1.6
 */
@Controller
public class SysStoreController {
    @Autowired
    SysStoreService sysStoreService;
    
    @Autowired
    SysLogService sysLogService;
    
    @RequestMapping(value="/sys-store-list.htmlx")
    public String  sysTaskList(ModelMap model,UsersBo usersBo){
        List list = sysStoreService.getAllStore(usersBo);
        model.addAttribute("list",list);
        model.addAttribute("usersBo",usersBo);
        return "sys/sys-store-list";
    }
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/sys-store-add.htmlx")
    public String  sysTaskAdd(ModelMap model,SysStore sysStore){
        if(sysStore.getId()==null||sysStore.getId()<1){
            model.addAttribute("store",sysStore);
            model.addAttribute("method","add");
            return "sys/sys-store-add";
        }
        SysStore info= sysStoreService.get(sysStore.getId());
        if(info!=null){
            model.addAttribute("store",info);
        }
        System.out.println("111111111111111");
        return "sys/sys-store-add";
    }
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/storeSave.htmlx")
    @ResponseBody
    public Map  taskSave(HttpServletRequest request ,ModelMap model,SysStore sysStore){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        sysLogService.add("更新任务", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        Map map =new HashMap();
        map.put("result", "success");
        sysStoreService.saveOrUpdate(sysStore);;
        System.out.println("111111111111111");
        return map;
    }
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/stopStore.htmlx")
    @ResponseBody
    public Map  stopTask(HttpServletRequest request ,SysStore sysStore){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        sysLogService.add("停止任务", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        sysStoreService.stopStore(sysStore);
        Map map =new HashMap();
        map.put("result", "success");
        return map;
    }
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/startStore.htmlx")
    @ResponseBody
    public Map  startTask(HttpServletRequest request ,SysStore sysStore){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        sysLogService.add("开启任务", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        sysStoreService.startStore(sysStore);
        Map map =new HashMap();
        map.put("result", "success");
        return map;
    }
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/deleteStore.htmlx")
    @ResponseBody
    public Map  deleteTask(HttpServletRequest request ,String ids){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        sysLogService.add("删除任务", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        Map map =new HashMap();
        if(ids!=null){
            String[] id=ids.split(",");
            for(String s:id){
                sysStoreService.delete(Long.valueOf(s));
            }
        }
        map.put("result", "success");
        System.out.println("111111111111111");
        return map;
    }
}
  